----------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\research\china\decentralization\restat_data\tabdata\dofiles\tab_da
> ta\tabdata2.log
  log type:  text
 opened on:  22 Jul 2016, 09:50:16

. 
. 
. ****************** 1. Prepare Data Sets to Merge to Correspondence Table *******
> ******************
. 
. ** Individual Yearbooks
. use ..\..\data\tabular_data_BJ\source\ind_yb_rz.dta

. drop if unit_status>3
(759 observations deleted)

. ***Delete the 4 duplicate obs: Second obs generally has numbers*100
. sort unit_code_08 year gdp

. by unit_code_08 year: keep if _n==1
(4 observations deleted)

. ***Fix these unit_status which are wrong
. replace unit_status=5 if unit_code_08==130200 & year==1995
(1 real change made)

. replace unit_status=5 if unit_code_08==130200 & year==2000
(0 real changes made)

. replace unit_status=5 if unit_code_08==130200 & year==2005
(0 real changes made)

. replace unit_status=4 if unit_code_08==130201 & year==1995
(1 real change made)

. replace unit_status=4 if unit_code_08==130201 & year==2000
(0 real changes made)

. replace unit_status=4 if unit_code_08==130201 & year==2005
(0 real changes made)

. replace unit_status=5 if unit_code_08==130400 & year==1995
(0 real changes made)

. replace unit_status=4 if unit_code_08==130401 & year==1995
(0 real changes made)

. replace unit_status=5 if unit_code_08==510300 & year==2000
(0 real changes made)

. replace unit_status=4 if unit_code_08==510301 & year==2000
(0 real changes made)

. replace unit_status=1 if unit_code_08==341602 & year==2000
(0 real changes made)

. drop if unit_status>3
(2 observations deleted)

. *** This obs was wrong
. replace unit_code_08=341600 if unit_code_08==341602 & year==2000
(0 real changes made)

. ***Extra obs with no information anyways
. drop if unit_code_08==530101 & unit_status==1
(3 observations deleted)

. sort unit_code_08 year

. save temp_indyb.dta, replace
(note: file temp_indyb.dta not found)
file temp_indyb.dta saved

. 
. **Michigan Online
. **Get county cities that were in the michigan data
. use ..\..\data\tabular_data_BJ\source\MI_4YCP.dta

. keep if city_code==441900 | city_code==442000 | city_code==341600
(1,065 observations deleted)

. sort city_code year

. save temp_mi3ycp.dta, replace
(note: file temp_mi3ycp.dta not found)
file temp_mi3ycp.dta saved

. 
. use ..\..\data\tabular_data_BJ\source\MI_ADCP.dta

. keep if city_code==441900 | city_code==442000 | city_code==341600
(3,752 observations deleted)

. keep if year==2000|year==2005|year==2008|year==2010
(29 observations deleted)

. sort city_code year

. merge using temp_mi3ycp.dta
(note: you are using old merge syntax; see [D] merge for new syntax)
(note: variable city_name was str29, now str34 to accommodate using data's
       values)
(note: variable city_code was float, now double to accommodate using data's
       values)

. tab _merge

     _merge |      Freq.     Percent        Cum.
------------+-----------------------------------
          3 |         12      100.00      100.00
------------+-----------------------------------
      Total |         12      100.00

. drop _merge

. replace unit_code_08 = 441900 if city_code==441900
(4 real changes made)

. replace unit_code_08 = 442000 if city_code==442000
(4 real changes made)

. replace unit_code_08 = 341600 if city_code==341600 & year==2000
(1 real change made)

. replace unit_code_08 = 341602 if city_code==341600 & year>2000
(3 real changes made)

. rename total_pop pop

. append using ..\..\data\tabular_data_BJ\source\MI_4YRC.dta
(note: variable unit was str39, now str59 to accommodate using data's values)
(note: variable province was str14, now str21 to accommodate using data's
       values)
(note: variable unit_name was str34, now str59 to accommodate using data's
       values)
(note: variable unit_code_08 was float, now double to accommodate using data's
       values)

. ** These are prefectures that we decided to drop
. drop if city_code==640100|city_code==640200|unit_code_08==640181
(0 observations deleted)

. rename gdp gdp_michigan

. rename avg_salary_of_staff_worker avgsalary_michigan

. 
. sort unit_code_08 year

. save temp_mi.dta, replace
(note: file temp_mi.dta not found)
file temp_mi.dta saved

. 
. *** Capital Investment data
. use ..\..\data\tabular_data_BJ\source\MI_InvCap00_01.dta

. keep unit_code_08 inv_cap year

. reshape wide inv_cap, i(unit_code_08) j(year)
(note: j = 2000 2001)

Data                               long   ->   wide
-----------------------------------------------------------------------------
Number of obs.                     3402   ->    1703
Number of variables                   3   ->       3
j variable (2 values)              year   ->   (dropped)
xij variables:
                                inv_cap   ->   inv_cap2000 inv_cap2001
-----------------------------------------------------------------------------

. gen year = 2000

. sort unit_code_08 year

. merge unit_code_08 year using temp_mi.dta
(note: you are using old merge syntax; see [D] merge for new syntax)

. tab year _merge

           |              _merge
      year |         1          2          3 |     Total
-----------+---------------------------------+----------
      2000 |         1          8      1,702 |     1,711 
      2005 |         0      1,710          0 |     1,710 
      2008 |         0      1,710          0 |     1,710 
      2010 |         0      1,709          0 |     1,709 
-----------+---------------------------------+----------
     Total |         1      5,137      1,702 |     6,840 


. ** the one _merge=1 is OK
. drop _merge

. sort unit_code_08 year

. save temp_mi.dta, replace
file temp_mi.dta saved

. 
. **1997 Villagers Committees
. use ..\..\data\tabular_data_BJ\source\MI_vc97_final.dta

. *** Drop unusable data b/c of changes 95-97
. *** Each is the result of a split, so data only partially covers a common code r
> egion
. drop if unit_code_08==431221
(1 observation deleted)

. drop if unit_code_08==445323
(1 observation deleted)

. drop if unit_code_08==450681
(1 observation deleted)

. drop if unit_code_08==450924
(1 observation deleted)

. drop if unit_code_08==510626
(1 observation deleted)

. drop if unit_code_08==623001
(1 observation deleted)

. replace year = 1995
(1,491 real changes made)

. ** These are prefectures that we decided to drop
. drop if city_code==640100|city_code==640200
(4 observations deleted)

. sort unit_code_08 year

. *** DROP REPEATED OBS, TO BE CLEANED UP LATER
. by unit_code_08 year: keep if _n==1
(15 observations deleted)

. sort unit_code_08 year

. save temp_vc97.dta, replace
(note: file temp_vc97.dta not found)
file temp_vc97.dta saved

. 
. **Fiscal 1995
. use ..\..\data\tabular_data_BJ\source\fiscal_95_rz.dta

. *** These codes were wrong
. replace unit_code_08 = 130902 if unit_code_08==130105 & city_code==130900
(1 real change made)

. drop if unit_code_08 == 130302 & city_code==130200
(1 observation deleted)

. replace unit_code_08 = 210303 if unit_code_08==210106 & city_code==210300
(1 real change made)

. replace unit_code_08 = 321324 if unit_code_08==321323 & rural_pop==85
(1 real change made)

. replace unit_name = "Sihong County" if unit_code_08==321324
(1 real change made)

. replace gdp = . if gdp<0
(0 real changes made)

. replace gdp_sector2 = . if gdp_sector2<0
(0 real changes made)

. rename gdp gdp_f95

. rename gdp_sector2 gdp_sector2_f95

. rename pop pop_f95

. rename rural_pop rural_pop_f95

. sort unit_code_08 year

. save temp_f95.dta, replace
(note: file temp_f95.dta not found)
file temp_f95.dta saved

. 
. **Fenxian 1990 (rural counties)
. use ..\..\data\tabular_data_BJ\source\fenxian_1990_rz.dta

. *** We can't merge this obs and it has no info on any variables
. drop if county_name=="Qujing City" & unit_code_08==-9 & year==1990
(1 observation deleted)

. *** These are repeated obs with a few numbers we won't use that are different
. drop if unit_code_08==231024 & unit_status==3
(1 observation deleted)

. drop if unit_code_08==231025 & fertilizer_1990==20213
(1 observation deleted)

. *** Rename these variables that overlap with those from ind_yb data
. rename gdp gdp_fenxian

. rename gdp_sec1 gdp_sector1_fenxian

. rename gdp_sec2 gdp_sector2_fenxian

. rename agr_mp agr_mp_fenxian

. rename ruralpop ruralpop_fenxian

. rename rurallabor rurallabor_fenxian

. sort unit_code_08 year

. save temp_fenxian.dta, replace
(note: file temp_fenxian.dta not found)
file temp_fenxian.dta saved

. ***Create alternative version to merge on names
. keep if unit_code_08==-9
(1,768 observations deleted)

. gen mrg1=1

. rename county_name unit_name

. sort mrg1 unit_name year

. save temp_fenxian2.dta, replace
(note: file temp_fenxian2.dta not found)
file temp_fenxian2.dta saved

. 
. ************************************************************
. ************************************************************
. ** Professor Zhang's 1. supplement_xian_updated.csv asset data  (HY 08/09/12)
. 
. insheet using ..\..\data\tabular_data_BJ\source\asset_supplement_xian.csv, clear
(13 vars, 7,427 obs)

. tab unit_status

unit_status |      Freq.     Percent        Cum.
------------+-----------------------------------
         -1 |         20        0.27        0.27
          0 |         43        0.58        0.85
          1 |      2,179       29.34       30.19
          2 |      4,254       57.28       87.46
          3 |        931       12.54      100.00
------------+-----------------------------------
      Total |      7,427      100.00

. 
. *** rename variables (add qz & shorted them)
. rename gross_asset_cp asset_g_qz

. rename net_asset_cp asset_n_qz

. 
. drop if asset_g_qz==. & asset_n_qz==.
(7,327 observations deleted)

. keep year unit_code_08 *_qz

. 
. sort unit_code_08 year

. save temp_qz1.dta, replace
(note: file temp_qz1.dta not found)
file temp_qz1.dta saved

. 
. *** This is for use in predicting net assets in 2000
. insheet using ..\..\data\tabular_data_BJ\source\asset_dijishi.csv, clear
(14 vars, 858 obs)

. drop if net_asset_cp==net_asset_pref
(192 observations deleted)

. drop if net_asset_pref==.
(6 observations deleted)

. keep if year==2000
(418 observations deleted)

. keep city05 year net_asset_pref net_asset_cp

. sort city05 year

. save assets00.dta, replace
(note: file assets00.dta not found)
file assets00.dta saved

. 
. 
. ************************************************************
. ************************************************************
. ** Professor Zhang's 2. county_23_6.csv asset data (HY 08/09/12)
. 
. insheet using ..\..\data\tabular_data_BJ\source\county_23_6.csv, clear
(24 vars, 29 obs)

. rename uc_08 unit_code_08

. 
. *** rename variables (add qz & shorted them)
. rename gross_asset_cp asset_g_qz

. rename net_asset_cp asset_n_qz

. rename gdp_cp gdp_qz

. rename gdp_s1_cp gdp_s1_qz

. rename gdp_s2_cp gdp_s2_qz

. rename gdp_s3_cp gdp_s3_qz

. rename fdi_cp fdi_qz

. rename soe_output_cp soe_output_qz

. rename total_output_cp total_output_qz

. 
. /* left for future use; some gdp and fdi variables are here
> rename gross_asset_pref10e4 asset_g_qz_pf
> rename net_asset_pref asset_n_qz_pf
> rename *_pref *_qz_pf
> rename *_pref10e4 *_qz_pf
> rename gross_asset_* asset_g_*
> rename net_asset_* asset_n_*
> rename gdp10e8_qz_pf gdp_qz_pf
> rename fdi10e4usd_qz_pf fdi_qz_pf
> */
. 
. keep unit_code_08 *_qz

. 
. gen year=1990

. 
. sort unit_code_08 year

. save temp_qz2.dta, replace
(note: file temp_qz2.dta not found)
file temp_qz2.dta saved

. 
. 
. 
. /*** Printed Yearbooks have some data for county cities up to 1997 (use only 90,
> 95)
> Identify obs in corr file that are potential PY obs.  Use city00 as the merge
> variable because the PY data is set up that way. **/
. use ..\..\data\correspondence_tables\generated\correspondence_82_10.dta

. keep if year<=2005
(4,982 observations deleted)

. egen urban05 = max((unit_status==1)*(year==2005)), by(unit_code_common)

. egen us = max(unit_status==1), by(city_code year)

. replace urban05 = 0 if us==1
(3,612 real changes made)

. #delimit ;
delimiter now ;
. keep if urban05==1|unit_code_08==341602|unit_code_08==422801|unit_code_08==43110
> 2
> |unit_code_08==441900|unit_code_08==442000|unit_code_08==451002|unit_code_08==45
> 1202
> |unit_code_08==522201|unit_code_08==530601|unit_code_08==620602|unit_code_08==62
> 0702
> |unit_code_08==620802|unit_code_08==620902|unit_code_08==321200|unit_code_08==32
> 1300
> |(unit_code_08==371200&year==1990)|(unit_code_08==445100&year==1990);
(11,828 observations deleted)

. #delimit cr
delimiter now cr
. keep if unit_status==3 & year<2000
(197 observations deleted)

. drop if unit_code_08==431103|unit_code_08==330110|unit_code_08==431103|unit_code
> _08==350681|unit_code_08==500066
(1 observation deleted)

. sort city05 year

. by city05 year: gen obs = _N

. tab obs

        obs |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |        207       98.10       98.10
          2 |          4        1.90      100.00
------------+-----------------------------------
      Total |        211      100.00

. drop if obs>1
(4 observations deleted)

. keep city05 unit_code_08 year city_name unit_name

. sort city05 year

. save tempcorr.dta, replace
(note: file tempcorr.dta not found)
file tempcorr.dta saved

. 
. use ..\..\data\tabular_data_BJ\source\PY_ADCP_final_rz.dta

. sort unit_code year

. save ..\..\data\tabular_data_BJ\source\PY_ADCP_final_rz.dta, replace
file ..\..\data\tabular_data_BJ\source\PY_ADCP_final_rz.dta saved

. use ..\..\data\tabular_data_BJ\source\PY_2YCP_final_rz.dta

. sort unit_code year 

. merge unit_code year using ..\..\data\tabular_data_BJ\source\PY_ADCP_final_rz.dt
> a, update
(note: you are using old merge syntax; see [D] merge for new syntax)

. tab _merge

     _merge |      Freq.     Percent        Cum.
------------+-----------------------------------
          2 |      1,986       66.67       66.67
          3 |        993       33.33      100.00
------------+-----------------------------------
      Total |      2,979      100.00

. drop _merge

. keep if year==1990|year==1995
(2,317 observations deleted)

. gen city05 = unit_code

. replace city05 = unit_code-100 if city05-10*int(city05/10)==0
(8 real changes made)

. replace city05 = unit_code-1 if city05-10*int(city05/10)==1
(654 real changes made)

. sort city05 year

. merge city05 year using tempcorr.dta
(note: you are using old merge syntax; see [D] merge for new syntax)

. tab _merge

     _merge |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |        519       71.49       71.49
          2 |         64        8.82       80.30
          3 |        143       19.70      100.00
------------+-----------------------------------
      Total |        726      100.00

. keep if _merge==3
(583 observations deleted)

. drop _merge unit_code city05 agremp-pubemp

. rename gdp gdp_py

. rename fdi fdi_py

. rename givo givo_py

. sort unit_code_08 year

. save temp_2ycp.dta, replace
(note: file temp_2ycp.dta not found)
file temp_2ycp.dta saved

. 
. *** Provincial GDP Data from 1990
. use ..\..\data\tabular_data_BJ\source\yearbook90.dta

. keep if year==1990
(26 observations deleted)

. ** This is Chongqing, part of Sichuan until 1997
. drop if province_code==500000
(1 observation deleted)

. keep province_code gdp_total gdp_sec1 gdp_sec2 gdp_sec3

. rename gdp_total pgdp

. rename gdp_sec1 pgdp_sec1

. rename gdp_sec2 pgdp_sec2

. rename gdp_sec3 pgdp_sec3

. rename province_code province_code90

. gen year = 1990

. sort province_code90 year

. save temp_p90.dta, replace
(note: file temp_p90.dta not found)
file temp_p90.dta saved

. 
. 
. /****** 2. Merge Data Sets to Correspondence Table Using 
>         Urban District, Rural County, County City Units Only ********/
. 
. use ..\..\data\correspondence_tables\generated\correspondence_82_10.dta

. 
. **** Individual Yearbook Data
. sort unit_code_08 year

. merge unit_code_08 year using temp_indyb.dta
(note: you are using old merge syntax; see [D] merge for new syntax)
variables unit_code_08 year do not uniquely identify observations in the master
    data

. sort year

. by year: tab unit_status _merge

----------------------------------------------------------------------------------
-> year = 1982

-1=spec.ru |
         r |
0=spec.urb |
1=urb.dist |
   2=rural |
 cty 3=cty |   _merge
      city |         1 |     Total
-----------+-----------+----------
         1 |       441 |       441 
         2 |     1,743 |     1,743 
         3 |       168 |       168 
-----------+-----------+----------
     Total |     2,352 |     2,352 


----------------------------------------------------------------------------------
-> year = 1990

-1=spec.ru |
         r |
0=spec.urb |
1=urb.dist |
   2=rural |
 cty 3=cty |              _merge
      city |         1          2          3 |     Total
-----------+---------------------------------+----------
        -1 |         5          0          0 |         5 
         0 |         3          0          0 |         3 
         1 |       460          5        151 |       616 
         2 |     1,387          0        177 |     1,564 
         3 |       231          0         22 |       253 
-----------+---------------------------------+----------
     Total |     2,086          5        350 |     2,441 


----------------------------------------------------------------------------------
-> year = 1995

-1=spec.ru |
         r |
0=spec.urb |
1=urb.dist |
   2=rural |
 cty 3=cty |              _merge
      city |         1          2          3 |     Total
-----------+---------------------------------+----------
        -1 |         8          0          1 |         9 
         0 |        12          0          0 |        12 
         1 |       404          2        263 |       669 
         2 |     1,190          0        205 |     1,395 
         3 |       300          0         86 |       386 
-----------+---------------------------------+----------
     Total |     1,914          2        555 |     2,471 


----------------------------------------------------------------------------------
-> year = 2000

-1=spec.ru |
         r |
0=spec.urb |
1=urb.dist |
   2=rural |
 cty 3=cty |              _merge
      city |         1          2          3 |     Total
-----------+---------------------------------+----------
        -1 |         7          0          0 |         7 
         0 |        17          0          1 |        18 
         1 |       382          3        364 |       749 
         2 |       957          1        407 |     1,365 
         3 |       204          0        150 |       354 
-----------+---------------------------------+----------
     Total |     1,567          4        922 |     2,493 


----------------------------------------------------------------------------------
-> year = 2005

-1=spec.ru |
         r |
0=spec.urb |
1=urb.dist |
   2=rural |
 cty 3=cty |        _merge
      city |         1          3 |     Total
-----------+----------------------+----------
        -1 |         8          0 |         8 
         0 |        17          5 |        22 
         1 |       377        428 |       805 
         2 |       882        446 |     1,328 
         3 |       170        158 |       328 
-----------+----------------------+----------
     Total |     1,454      1,037 |     2,491 


----------------------------------------------------------------------------------
-> year = 2008

-1=spec.ru |
         r |
0=spec.urb |
1=urb.dist |
   2=rural |
 cty 3=cty |        _merge
      city |         1          3 |     Total
-----------+----------------------+----------
        -1 |         8          0 |         8 
         0 |        18          4 |        22 
         1 |       471        341 |       812 
         2 |     1,047        280 |     1,327 
         3 |       219        104 |       323 
-----------+----------------------+----------
     Total |     1,763        729 |     2,492 


----------------------------------------------------------------------------------
-> year = 2010

-1=spec.ru |
         r |
0=spec.urb |
1=urb.dist |
   2=rural |
 cty 3=cty |   _merge
      city |         1 |     Total
-----------+-----------+----------
        -1 |         8 |         8 
         0 |        22 |        22 
         1 |       809 |       809 
         2 |     1,328 |     1,328 
         3 |       323 |       323 
-----------+-----------+----------
     Total |     2,490 |     2,490 



. rename _merge mrg_ind

. sort unit_status unit_code_08

. /*** These are the individual yearbook codes for which 
> there is no code in the correspondence file and for whom we do
> not have a geography, even those listed for 2005.  Because the
> remaining units merged perfectly in each city code affected, drop these. ****/
. l unit_code_08 unit_name unit_status year if mrg_ind==2

       +--------------------------------------------------+
       | unit_~08             unit_name   unit_s~s   year |
       |--------------------------------------------------|
 1953. |   320507   Xiangcheng District          1   2000 |
 1955. |   320552          Xin District          1   2000 |
 2110. |   330108     Binjiang District          1   1990 |
 2113. |   330108     Binjiang District          1   1995 |
 3987. |   440512     Haojiang District          1   1995 |
       |--------------------------------------------------|
 3989. |   440512     Haojiang District          1   2000 |
 4446. |   510104     Jinjiang District          1   1990 |
 4448. |   510105     Qingyang District          1   1990 |
 4462. |   510107        Wuhou District          1   1990 |
 4468. |   510108     Chenghua District          1   1990 |
       |--------------------------------------------------|
 7396. |   320553             Wu County          2   2000 |
       +--------------------------------------------------+

. drop if mrg_ind==2
(11 observations deleted)

. 
. **** Michigan Online Data (rural county and city data, 2000-2008 Only)
. sort unit_code_08 year

. merge unit_code_08 year using temp_mi.dta
(note: you are using old merge syntax; see [D] merge for new syntax)
variables unit_code_08 year do not uniquely identify observations in the master
    data
(note: variable year was int, now float to accommodate using data's values)
(note: variable city_name was str29, now str34 to accommodate using data's
       values)
(note: variable unit_status was byte, now float to accommodate using data's
       values)
(note: variable city_code was long, now double to accommodate using data's
       values)
(note: variable unit_name was str55, now str59 to accommodate using data's
       values)
(note: variable gdp_sector2 was float, now double to accommodate using data's
       values)
(note: variable gdp_sector3 was float, now double to accommodate using data's
       values)

. tab unit_status _merge if year>1995

-1=spec.ru |
         r |
0=spec.urb |
1=urb.dist |
   2=rural |
 cty 3=cty |        _merge
      city |         1          3 |     Total
-----------+----------------------+----------
        -1 |        23          8 |        31 
         0 |        84          0 |        84 
         1 |     2,992        180 |     3,172 
         2 |        22      5,325 |     5,347 
         3 |         1      1,327 |     1,328 
-----------+----------------------+----------
     Total |     3,122      6,840 |     9,962 


. rename _merge mrg_MI3Yrc

. ** These missings are backed out by comparing the PF and county data
. * Urban Units
. replace gdp_michigan = 37.96 if unit_code_08==140602 & year==2000
(1 real change made)

. replace gdp_michigan = 63.75 if unit_code_08==360313 & year==2000
(1 real change made)

. replace gdp_michigan = 73.23 if unit_code_08==440660 & year==2000
(1 real change made)

. replace gdp_michigan = 88.73 if unit_code_08==140602 & year==2005
(1 real change made)

. replace gdp_michigan = 17.66 if unit_code_08==230624 & year==2005
(1 real change made)

. replace gdp_michigan = 129.98 if unit_code_08==360313 & year==2005
(1 real change made)

. *Rural Units
. replace gdp_michigan = 49.31 if unit_code_08==230111 & year==2000
(1 real change made)

. replace gdp_michigan = 138.95 if unit_code_08==320506 & year==2000
(1 real change made)

. replace gdp_michigan = 37.37 if unit_code_08==321311 & year==2000
(1 real change made)

. replace gdp_michigan = 97.6 if unit_code_08==350304.5 & year==2000
(1 real change made)

. replace gdp_michigan = 24.76 if unit_code_08==640502 & year==2000
(1 real change made)

. *** THese are two adjacent special districts which I split residual GDP evenly a
> cross
. replace gdp_michigan = 13.31 if (unit_code_08==130904|unit_code_08==130905)& yea
> r==2005
(2 real changes made)

. replace gdp_michigan = 13.82 if unit_code_08==410188 & year==2005
(1 real change made)

. ** Special rural district
. replace gdp_michigan = 23.43 if unit_code_08==520203 & year==2005
(1 real change made)

. ** Assign remaining special districts GDP of 0
. replace gdp_michigan = 0 if unit_status==-1 & year>=2000 & gdp_michigan==.
(22 real changes made)

. 
. sort year unit_status unit_code_08

. *** These are the rural counties and county cities that should be in the MI data
>  but are not
. l unit_code_08 city_name city_code unit_name unit_status year if mrg_MI3Yrc==1 &
>  year>1995 & unit_status>1 & gdp_michigan==.

       +---------------------------------------------------------------+
 8330. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232701 | Daxing'anling Area |   232700 | Jiagedaqi District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2000             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
 8331. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232702 | Daxing'anling Area |   232700 |  Songling District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2000             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
 8332. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232703 | Daxing'anling Area |   232700 |    Xinlin District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2000             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
 8333. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232704 | Daxing'anling Area |   232700 |   Huzhong District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2000             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
 9385. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   640402 |        Guyuan Area |   642200 |      Guyuan County |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2000             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
10877. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232701 | Daxing'anling Area |   232700 | Jiagedaqi District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2005             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
10878. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232702 | Daxing'anling Area |   232700 |  Songling District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2005             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
10879. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232703 | Daxing'anling Area |   232700 |    Xinlin District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2005             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
10880. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232704 | Daxing'anling Area |   232700 |   Huzhong District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2005             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
13374. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232701 | Daxing'anling Area |   232700 | Jiagedaqi District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2008             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
13375. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232702 | Daxing'anling Area |   232700 |  Songling District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2008             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
13376. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232703 | Daxing'anling Area |   232700 |    Xinlin District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2008             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
13377. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232704 | Daxing'anling Area |   232700 |   Huzhong District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2008             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
15863. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232701 | Daxing'anling Area |   232700 | Jiagedaqi District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2010             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
15864. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232702 | Daxing'anling Area |   232700 |  Songling District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2010             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
15865. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232703 | Daxing'anling Area |   232700 |    Xinlin District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2010             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
15866. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   232704 | Daxing'anling Area |   232700 |   Huzhong District |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2010             |
       +---------------------------------------------------------------+

       +---------------------------------------------------------------+
16283. | unit_~08 |          city_name | city_c~e |          unit_name |
       |   421321 |            Suizhou |   421300 |         Sui County |
       |---------------------------------------------------------------|
       |            unit_s~s             |            year             |
       |                   2             |            2010             |
       +---------------------------------------------------------------+

. 
. **** VC97 Data
. sort unit_code_08 year

. merge unit_code_08 year using temp_vc97.dta
(note: you are using old merge syntax; see [D] merge for new syntax)
variables unit_code_08 year do not uniquely identify observations in the master
    data

. tab unit_status _merge if year==1995

-1=spec.ru |
         r |
0=spec.urb |
1=urb.dist |
   2=rural |
 cty 3=cty |        _merge
      city |         1          3 |     Total
-----------+----------------------+----------
        -1 |         7          2 |         9 
         0 |        12          0 |        12 
         1 |       660          7 |       667 
         2 |       213      1,182 |     1,395 
         3 |       105        281 |       386 
-----------+----------------------+----------
     Total |       997      1,472 |     2,469 


. rename _merge mrg_VC97

. 
. **** FY95 Data
. sort unit_code_08 year

. merge unit_code_08 year using temp_f95.dta, update
(note: you are using old merge syntax; see [D] merge for new syntax)
variables unit_code_08 year do not uniquely identify observations in the master
    data

. tab _merge if year==1995

     _merge |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |        395       15.84       15.84
          2 |         24        0.96       16.81
          3 |      1,731       69.43       86.24
          4 |          2        0.08       86.32
          5 |        341       13.68      100.00
------------+-----------------------------------
      Total |      2,493      100.00

. ** There are no names for these obs so they can't be merged
. drop if _merge==2
(24 observations deleted)

. rename _merge mrg_f95

. 
. **** PY Data
. sort unit_code_08 year

. merge unit_code_08 year using temp_2ycp.dta
(note: you are using old merge syntax; see [D] merge for new syntax)
variables unit_code_08 year do not uniquely identify observations in the master
    data

. tab year _merge if year<2000

           |        _merge
      year |         1          3 |     Total
-----------+----------------------+----------
      1982 |     2,352          0 |     2,352 
      1990 |     2,356         80 |     2,436 
      1995 |     2,406         63 |     2,469 
-----------+----------------------+----------
     Total |     7,114        143 |     7,257 


. rename _merge mrg_2ycp

. 
. **** Fenxian 1990 Data (rural county and county city data, 1990 Only)
. sort unit_code_08 year

. merge unit_code_08 year using temp_fenxian.dta
(note: you are using old merge syntax; see [D] merge for new syntax)
variables unit_code_08 year do not uniquely identify observations in the master
    data
variables unit_code_08 year do not uniquely identify observations in
    temp_fenxian.dta

. tab _merge unit_status if year==1990 & unit_status>1

           |      -1=spec.rur
           | 0=spec.urb 1=urb.dist
           |   2=rural cty 3=cty
           |         city
    _merge |         2          3 |     Total
-----------+----------------------+----------
         1 |        26         29 |        55 
         2 |        19         15 |        34 
         3 |     1,538        224 |     1,762 
-----------+----------------------+----------
     Total |     1,583        268 |     1,851 


. rename _merge mrg_fenxian

. tab unit_code_08 if mrg_fenxian==2

  unit code |
       at t |      Freq.     Percent        Cum.
------------+-----------------------------------
         -9 |         28       82.35       82.35
     350527 |          1        2.94       85.29
     510923 |          1        2.94       88.24
     640121 |          1        2.94       91.18
     640122 |          1        2.94       94.12
     640205 |          1        2.94       97.06
     640221 |          1        2.94      100.00
------------+-----------------------------------
      Total |         34      100.00

. drop if mrg_fenxian==2
(34 observations deleted)

. ***** For the bad merges, we can merge on unit name instead
. gen mrg1 = (mrg_fenxian==1 & year==1990 & unit_status>1)

. sort mrg1 unit_name year

. by mrg1 unit_name year: gen obs = _N

. replace mrg1 = 0 if obs>2
(0 real changes made)

. sort mrg1 unit_name year

. merge mrg1 unit_name year using temp_fenxian2.dta, update
(note: you are using old merge syntax; see [D] merge for new syntax)
variables mrg1 unit_name year do not uniquely identify observations in the
    master data

. tab _merge unit_status if year==1990 & unit_status>1 & mrg1==1

           |      -1=spec.rur
           | 0=spec.urb 1=urb.dist
           |   2=rural cty 3=cty
           |         city
    _merge |         2          3 |     Total
-----------+----------------------+----------
         1 |        15         13 |        28 
         2 |         1          0 |         1 
         5 |        11         16 |        27 
-----------+----------------------+----------
     Total |        27         29 |        56 


. replace mrg_fenxian=3 if _merge==5
(27 real changes made)

. drop if _merge==2
(1 observation deleted)

. replace mrg_fenxian = 3 if _merge==5
(0 real changes made)

. drop _merge

. 
. ** supplement_xian
. sort unit_code_08 year

. merge unit_code_08 year using temp_qz1.dta
(note: you are using old merge syntax; see [D] merge for new syntax)
variables unit_code_08 year do not uniquely identify observations in the master
    data

. tab year _merge

           |        _merge
      year |         1          3 |     Total
-----------+----------------------+----------
      1982 |     2,352          0 |     2,352 
      1990 |     2,337         99 |     2,436 
      1995 |     2,469          0 |     2,469 
      2000 |     2,488          1 |     2,489 
      2005 |     2,491          0 |     2,491 
      2008 |     2,492          0 |     2,492 
      2010 |     2,490          0 |     2,490 
-----------+----------------------+----------
     Total |    17,119        100 |    17,219 


. rename _merge mrg_qz1

. 
. ** county_23_6.csv extra data on some county cities
. sort unit_code_08 year

. merge unit_code_08 year using temp_qz2.dta, update
(note: you are using old merge syntax; see [D] merge for new syntax)
variables unit_code_08 year do not uniquely identify observations in the master
    data

. tab year _merge

           |                   _merge
      year |         1          3          4          5 |     Total
-----------+--------------------------------------------+----------
      1982 |     2,352          0          0          0 |     2,352 
      1990 |     2,407         26          2          1 |     2,436 
      1995 |     2,469          0          0          0 |     2,469 
      2000 |     2,489          0          0          0 |     2,489 
      2005 |     2,491          0          0          0 |     2,491 
      2008 |     2,492          0          0          0 |     2,492 
      2010 |     2,490          0          0          0 |     2,490 
-----------+--------------------------------------------+----------
     Total |    17,190         26          2          1 |    17,219 


. rename _merge mrg_qz2

. 
. **** Consolidate these gdp variables
. replace gdp_py = gdp_qz if gdp_py==. | gdp_py==-9
(44 real changes made, 18 to missing)

. replace gdp_sect2 = gdp_s2_qz if gdp_sect2==. | gdp_sect2==-9
(44 real changes made, 18 to missing)

. replace gdp_sect3 = gdp_s3_qz if gdp_sect3==. | gdp_sect3==-9
(44 real changes made, 18 to missing)

. drop gdp_qz gdp_s1_qz gdp_s2_qz gdp_s3_qz

. 
. **** Merge on CP and PF level asset data 
. sort city05 year

. merge city05 year using assets00.dta
(note: you are using old merge syntax; see [D] merge for new syntax)
variables city05 year do not uniquely identify observations in the master data
(note: variable city05 was float, now double to accommodate using data's values)

. tab year _merge 

           |        _merge
      year |         1          3 |     Total
-----------+----------------------+----------
      1982 |     2,352          0 |     2,352 
      1990 |     2,436          0 |     2,436 
      1995 |     2,469          0 |     2,469 
      2000 |       338      2,151 |     2,489 
      2005 |     2,491          0 |     2,491 
      2008 |     2,492          0 |     2,492 
      2010 |     2,490          0 |     2,490 
-----------+----------------------+----------
     Total |    15,068      2,151 |    17,219 


. drop _merge

. egen sinv_cap2000 = sum(inv_cap2000), by(city05 year)

. replace asset_n_qz = (net_asset_pref-net_asset_cp)*(inv_cap2000/sinv_cap2000) if
>  asset_n_qz==.
variable asset_n_qz was long now double
(1,410 real changes made)

. drop net_asset_cp net_asset_pref sinv_cap2000

. 
. **** Merge on asset data that was recorded for yet to be promoted CPs
. sort city05 year

. merge city05 year using ../../data/tabular_data_BJ/generated/asset_data.dta
(note: you are using old merge syntax; see [D] merge for new syntax)
variables city05 year do not uniquely identify observations in the master data

. tab _merge

     _merge |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |     16,636       96.61       96.61
          3 |        583        3.39      100.00
------------+-----------------------------------
      Total |     17,219      100.00

. gen mrgobs = cp90==1 & (unit_status==1 | unit_status==3)

. egen Mrgobs = max(mrgobs), by(city05 year)

. tab Mrgobs if _merge==3

     Mrgobs |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |          8        1.37        1.37
          1 |        575       98.63      100.00
------------+-----------------------------------
      Total |        583      100.00

. replace asset_n_qz = asset_n_qzx if cp90==1 & (unit_status==1|unit_status==3)
(30 real changes made, 24 to missing)

. replace asset_g_qz = asset_g_qzx if cp90==1 & (unit_status==1|unit_status==3)
(21 real changes made, 20 to missing)

. replace asset_n_qz = asset_n_qzx if cp90==1 & unit_name=="Qujing City"
(0 real changes made)

. replace asset_g_qz = asset_g_qzx if cp90==1 & unit_name=="Qujing City"
(0 real changes made)

. drop asset_n_qzx asset_g_qzx mrgobs Mrgobs _merge

. 
. *** Recode error values to missing
. #delimit ;
delimiter now ;
. mvdecode totemp-fixinvest agr_mp ruralpop rurallabor agr_rl cularea fertilizer_1
> 990 rurele 
> gdp_fenxian gdp_sector1_fenxian gdp_sector2_fenxian pop_f95 rural_pop_f95 fdi_py
> ruralpop_fenxian rurallabor_fenxian agr_mp_fenxian, mv(-9);
      totemp: 28 missing values generated
   total_pop: 28 missing values generated
        kmpr: 98 missing values generated
         apr: 74 missing values generated
        prpc: 29 missing values generated
      num_bt: 42 missing values generated
   avgsalary: 29 missing values generated
  num_colstd: 43 missing values generated
     givo_py: 28 missing values generated
    givo_soe: 73 missing values generated
   givo_colt: 73 missing values generated
     exp_lgt: 11 missing values generated
    num_hedu: 20 missing values generated
   publibcol: 12 missing values generated
     culland: 80 missing values generated
        area: 10 missing values generated
   emp_sect2: 28 missing values generated
   emp_sect3: 28 missing values generated
   fixinvest: 21 missing values generated
      agr_rl: 18 missing values generated
     cularea: 18 missing values generated
fertili~1990: 19 missing values generated
      rurele: 14 missing values generated
 gdp_fenxian: 17 missing values generated
gd~1_fenxian: 17 missing values generated
gd~2_fenxian: 20 missing values generated
rural_pop~95: 51 missing values generated
      fdi_py: 83 missing values generated
ruralpop_f~n: 18 missing values generated
rurallabor~n: 18 missing values generated
agr_mp_fen~n: 13 missing values generated

. #delimit cr
delimiter now cr
. drop unit province county_name

. 
. *** Create sector 3 fenxian variable
. gen gdp_sector3_fenxian = gdp_fenxian-gdp_sector1_fenxian-gdp_sector2_fenxian
(15,458 missing values generated)

. replace gdp_sector3_fenxian = 0 if gdp_sector3_fenxian<0
(19 real changes made)

. 
. *** Merge on provincial level GDP data
. gen province_code90 = province_code

. replace province_code90 = 510000 if province_code90==500000
(244 real changes made)

. sort province_code90 year

. merge province_code90 year using temp_p90.dta
(note: you are using old merge syntax; see [D] merge for new syntax)
variables province_code90 year do not uniquely identify observations in the
    master data
(note: variable province_code90 was float, now double to accommodate using
       data's values)

. tab _merge if year==1990

     _merge |      Freq.     Percent        Cum.
------------+-----------------------------------
          3 |      2,436      100.00      100.00
------------+-----------------------------------
      Total |      2,436      100.00

. drop _merge

. 
. ** Drop variables with no obs
. drop mrg1 obs r08_nnp aproad bustrly numhins

. 
. *** Populate city_name variable over all urban observations
. sort city_code city_name

. by city_code: replace city_name = city_name[1]
(2,191 real changes made)

. replace city_name = "Hengshui" if city_code==131100
(0 real changes made)

. replace city_name = "Rizhao" if city_code==371100
(20 real changes made)

. 
. *** Label variables
. label variable gdp "(ind yrbk)"

. label variable nnp "(ind yrbk)"

. label variable gdp_sector1 "(ind yrbk)"

. label variable nnp_sector1 "(ind yrbk)"

. label variable gdp_sector2 "(ind yrbk)"

. label variable nnp_sector2 "(ind yrbk)"

. label variable gdp_sector3 "(ind yrbk)"

. label variable nnp_sector3 "(ind yrbk)"

. label variable tot_pop "(ind yrbk)"

. label variable r08_gdp "(ind yrbk)"

. label variable r08_gdp_sector2 "(ind yrbk)"

. label variable r08_nnp_sector2 "(ind yrbk)"

. label variable r08_gdp_sector3 "(ind yrbk)"

. label variable r08_nnp_sector3 "(ind yrbk)"

. label variable r08_tot_pop "(ind yrbk)"

. label variable arrived_fdi "(ind yrbk)"

. label variable tot_emp "(ind yrbk)"

. label variable tot_emp_sect2 "(ind yrbk)"

. label variable tot_emp_sect3 "(ind yrbk)"

. label variable num_car "(ind yrbk)"

. label variable dust_ems "(ind yrbk)"

. label variable so2 "(ind yrbk)"

. label variable giov "(ind yrbk)"

. label variable giov_soecol "(ind yrbk)"

. label variable tot_area "(ind yrbk)"

. label variable giov_new "(ind yrbk)"

. label variable giov_soecol_new "(ind yrbk)"

. label variable agr_mp "Total Agricultural Machinery Power (10000 Kw) (Michigan)"

. label variable pop "Population at Year-end (10000 persons) (Michigan)"

. label variable ruralpop "Rural Population at yr end (10000 persons) (Michigan)"

. label variable rurallabor "Number of rural laborers (10000 persons) (Michigan)"

. label variable gdp_michigan "gdp (100 millian yuan) (Michigan)"

. label variable va_sec1 "Value Added of Primary Industry (100 million yuan) (Mich
> igan)"

. label variable va_sec2 "Value Added of Secondary Industry (100 million yuan) (Mi
> chigan)"

. label variable expval "Value of Exports (1,000 US Dollars) (Michigan)"

. label variable inv_cap2000 "Capital investment, 2000"

. label variable inv_cap2001 "Capital investment, 2001"

. label variable agr_rl "(fenxian)"

. label variable cularea "(fenxian)"

. label variable fertilizer_1990 "(fenxian)"

. label variable rurele "(fenxian)"

. label variable gdp_fenxian "(fenxian)"

. label variable gdp_sector1_fenxian "(fenxian)"

. label variable gdp_sector2_fenxian "(fenxian)"

. label variable gdp_f95 "(95 fiscal yearbook)"

. label variable gdp_sector2_f95 "(95 fiscal yearbook)"

. label variable pop_f95 "(95 fiscal yearbook)"

. label variable rural_pop_f95 "(95 fiscal yearbook)"

. label variable totemp " (py)"

. label variable gdp_py " (py)"

. label variable gdp_sect2 " (py)"

. label variable gdp_sect3 " (py)"

. label variable total_pop " (py)"

. label variable kmpr " (py)"

. label variable apr " (py)"

. label variable prpc " (py)"

. label variable num_bt " (py)"

. label variable avgsalary " (py)"

. label variable num_colstd " (py)"

. label variable givo " (py)"

. label variable givo_soe " (py)"

. label variable givo_colt " (py)"

. label variable exp_lgt " (py)"

. label variable num_hedu " (py)"

. label variable publibcol " (py)"

. label variable culland " (py)"

. label variable area " (py)"

. label variable emp_sect2 " (py)"

. label variable emp_sect3 " (py)"

. label variable fixinvest " (py)"

. label variable fdi_py " (py)"

. label variable givo_py " (py)"

. label variable asset_g_qz " gross value of assets (py) "

. label variable asset_n_qz " net value of assets (py) "

. label variable pgdp "Provincial GDP"

. label variable pgdp_sec1 "Provincial GDP, Sector 1"

. label variable pgdp_sec2 "Provincial GDP, Sector 2"

. label variable pgdp_sec3 "Provincial GDP, Sector 3"

. 
. *** Special districts typically only record GDP and not population -> set pop to
>  0
. replace pop = 0 if unit_status==0 | unit_status==-1
(144 real changes made)

. replace pop_f95 = 0 if unit_status==0 | unit_status==-1
(144 real changes made)

. replace tot_pop = 0 if unit_status==0 | unit_status==-1
(144 real changes made)

. 
. *** This is the full disaggregate data set
. sort unit_code_08 year

. save ..\..\data\tabular_data_BJ\generated\us123.dta, replace
file ..\..\data\tabular_data_BJ\generated\us123.dta saved

. 
. log close
      name:  <unnamed>
       log:  C:\research\china\decentralization\restat_data\tabdata\dofiles\tab_da
> ta\tabdata2.log
  log type:  text
 closed on:  22 Jul 2016, 09:50:17
----------------------------------------------------------------------------------
